package com.ylt.assistedClass;

import java.util.concurrent.CountDownLatch;

public class ContDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {

        CountDownLatch countDownLatch = new CountDownLatch(5);

        for (int i = 1; i <= 5; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "run");
                countDownLatch.countDown();  //数量-1
            }, String.valueOf(i)).start();
        }

        countDownLatch.await();  //等待计数器归零，再向下执行

        System.out.println("关门");
    }
}
